if element in sight, do something

余生颓废 提交于 2019-12-24 02:59:07

问题


I have a slider. It animates things inside of layers. It also animates layers. So; what i want is when video layer comes sight, and it animates video itself from out of slider area; i need to do something.

This is what i have done so far. But it doesn't work.

if ($(".homeBannerVideoBg").live().is(":inView")) {
    $("body").addClass("YEEHA");
}
else {
    $("body").addClass("VUUHUU");
}

homeBannerVideoBg is my video element.

Can i get a hand over here ?


回答1:


https://github.com/protonet/jquery.inview

There's a great plugin, for determining when an element comes into the view when the user scrolls through the page. It takes the form of an event, so you can use a callback to perform your actions, just as you would a "click"




回答2:


try :visible

   if ($(".homeBannerVideoBg").is(":visible")) { 
        $("body").addClass("YEEHA"); 
   } 
   else { 
        $("body").addClass("VUUHUU"); 
   }


来源:https://stackoverflow.com/questions/11031724/if-element-in-sight-do-something

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!