【问题标题】:jQuery slide a DIV out when scroll to anchor tag ~jQuery滚动到锚标签时滑出一个DIV〜
【发布时间】:2012-12-14 05:20:14
【问题描述】:

我想在定义的页面区域内滑动一个包含内容的 DIV;在一个长的垂直 1 页网站内。

我设置了 6 个 DIV 块;

Block 5 我有一个包含在 DIV 中的 CSS3 / jQuery 动画——我想用 jQuerySLIDE 进入页面(从左侧或右侧)。

我正在考虑从定义的锚点确定滑动点;放在我希望 DIV 滑入的区域的标记内。

我怎么会写这个;

..类似于 -- if 锚标签;滑入?

类似的东西;

  slideLeftHide: function() {
    return this.each(function() {
      $(this).hide('slide', {direction: 'left'}, 1000);
    });

【问题讨论】:

标签: javascript jquery css


【解决方案1】:

http://jsfiddle.net/SZ8uH/2/

试试这样的:

var animInTriggeredAt = $("a#slidein").offset().top; //show when the anchor comes on stage
var animOutTriggeredAt = animInTriggeredAt + $(window).height(); //hide when it leaves the stage
var animActive = false;

// handle scroll event
$(window).scroll(checkScrollCues);

function checkScrollCues(){
    var scrollY = $(window).scrollTop();
    if (scrollY > animInTriggeredAt && scrollY < animOutTriggeredAt && !animActive){
        animActive = true;
        $("#myAnimatedDiv").show(); //put whatever animation code you want in here
    } else if ((scrollY < animInTriggeredAt || scrollY > animOutTriggeredAt) && animActive){
         animActive = false;
        $("#myAnimatedDiv").hide(); //put whatever animation code you want in here
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-26
    • 1970-01-01
    • 2014-08-08
    • 1970-01-01
    • 2013-10-01
    相关资源
    最近更新 更多