当Div被另一个div重叠时,禁用onclick / mousedown

时间:2014-01-10 11:17:52

标签: javascript jquery html css

我有一个循环功能,可以在第3个滑动2个div。可以在此处找到工作示例:http://jsbin.com/OYebomEB/4/

主要功能:

    var elements = ['#pointsbarDiv', '#hotlink1Div', '#pointsbarDiv', '#hotlink2Div'];
    function hotlinks_loop(index) {
        $(elements[index]).css({top: -75, display: 'block'}).animate({top: '+0'}, 3000, function () {
            var $self = $(this);
            var currentInstance = this;
            setTimeout(function () {
                $self.animate({top: $(window).height()}, 3000);
                if(currentInstance.hotlinkStop !== true){
                    hotlinks_loop((index + 1) % elements.length);
                }
            }, 3000, currentInstance);
        });
    }
        hotlinks_loop(0); // start with the first element

我有一些代码可以在hotlink div移动时禁用onclick:

hotlink2BtnClick: function () {
    if ($("#hotlink2Div").css("top") === "0px") {
        //do stuff;
    } else {
        //do stuff;
    }
},

然而,对于静止的pointbarDiv我找不到解决方案来禁用onclick / mousedown而hotlink divs滑过它。

我尝试了各种'If,如下例:

if (($("#hotlink1Div").css("top") < "76px" && $("#hotlink1Div").css("bottom") < "150px") || ($("#hotlink1Div").css("top") > "-75px" &&     $("#hotlink1Div").css("bottom") < "75px")))...

我也想知道是否有办法我可以在div提供的主要功能中禁用onclick / mousedown。

我应该提一下,我是javascript / jquery的新手。

2 个答案:

答案 0 :(得分:1)

JQuery事件函数传递给一个事件对象 - 你可以在你的函数中接受它,并使用它来阻止传播:

hotlink2BtnClick: function (ev) {
    ev.stopPropagation();

http://api.jquery.com/event.stoppropagation/

另外,如果你将你的js示例放在http://jsfiddle.net上,那么我们可以将它分叉并将其返回给你。

答案 1 :(得分:0)

我设法通过创建一个额外的div来实现这一点,它给它一个-1的z-index并设置隐藏的可见性。

然后用循环中的数组替换点div。

接下来实现类似的代码解决方案hotlink2BtnClick()。

相关问题