我有一個調用#notify
DIV功能。當我點擊任何地方以外的任何地方時,我怎樣才能讓div靠近?
當用戶點擊這個div,該函數被調用。然後當用戶再次點擊同一個div時,該功能被隱藏(使用切換)。
我不知道我怎麼會用這個相同的功能,而是有一個點擊關閉元素,所以如果用戶關閉點擊,股利是隱藏的。
簡而言之 當用戶點擊div(小方塊)時調用一個函數(一個Big方塊出現在小方塊的下方),除去大方塊的唯一方法是再次點擊小方塊。當用戶點擊大框外的任何地方時,我想讓大框隱藏。
<script>
$(document).ready(function() {
var notify = $("#notify");
var notifyLink = $("#notify_link");
var result = $("#result");
var loader = $('#loader');
var count = $("#count");
notify.hide();
notify.click(function(event) {
// Handle the click on the notify div so the document click doesn't close it
event.stopPropagation();
});
notifyLink.click(
function() { notify.toggle(notify.css('display') == 'none');
loader.html('<?php echo elgg_view('ajax/loader',array('slashes' => true)); ?>');
result.load("<?php echo $vars['url']; ?>mod/notifications/ajax/data.php",function(){
loader.empty(); // remove the loading gif
});
});
notifyLink.toggle(
function() {
$(this).addClass("selected");
},
function() {
$(this).removeClass("selected");
});
count.load("<?php echo $vars['url']; ?>mod/notifications/ajax/livenum.php");
var refreshId = setInterval(function() {
count.load("<?php echo $vars['url']; ?>mod/notifications/ajax/livenum.php");
}, 2500);
$.ajaxSetup({ cache: false });
});
</script>
<a href="#" id="notify_link"> </a><span id="count"></span>
<div id="notify" style="display:none;">
<h4>Notifications</h4>
<div id="loader"></div>
<div id="result" style="width:100%; height:100%;"></div>
<div class="seeall"><a href="<?php echo $vars['url']; ?>mod/notifications/all.php">See All Notifications</a></div>
</div>
你能提供HTML的身體呢?而且我對你所問的問題感到困惑,你能否詳細說明「有一個非點擊元素,所以如果用戶關閉點擊div是隱藏的」? – 2011-12-15 01:06:47
當用戶點擊DIV(小盒)一個funtion被調用(出現在小盒子的下面一大盒),除去大箱子的唯一方法是對小框中再次單擊。當用戶點擊大框外的任何地方時,我想讓大框隱藏。我希望這是有道理的。 – 2011-12-15 01:13:05
對代碼進行了格式化,使其更具可讀性。由於jsbeautifier不會忽略嵌入在php標籤中的```標記,因此必須經過多次傳遞。 – 2011-12-15 01:47:14