jquery 滚动到指定位置触发动画

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>sas</title>
<script type="text/javascript" src="js/jquery.js"></script>
<style type="text/css">
*{ margin:0px; padding:0px;}
.gs{
position:relative;
top:800px;
background-color:#099;
left:150px; width:80px;
}
.xz{

animation:roate 2s;
animation-fill-mode:forwards;
animation-direction:alternate;
	}

@keyframes roate{
	from { transform:rotate(0deg);
	width:100px;
    height:100px; }
	to{transform:rotate(360deg);
	width:200px;
    height:200px;
	}}
.xs{ width:50px; float: left; height:30px; background-color: #F90; position:fixed; left:700px; top:0px;}

</style>
</head>

<body>
<script type="text/javascript">
function gdjz(div,cssname,offset){
	var a,b,c,d;
	d=$(div).offset().top;
	a=eval(d + offset);
	b=$(window).scrollTop();
	c=$(window).height();
	if(b+c>a){
		$((div)).addClass((cssname));
		}
	}

$(document).ready(function(e) {
$(window).scroll(function(){
	gdjz("#dh",'xz',100);
	}

/*var a,b,c;
a=$("#dh").offset().top;//元素相对于窗口的距离
b=$(window).scrollTop(); //监控窗口已滚动的距离;
c=$(document).height();//整个文档的高度
d=$(window).height();//浏览器窗口的高度*/

/*if(d+b>a+100){
	$("#dh").addClass("xz");
	}
*/
	);
});
</script>
<div style="height:1800px; background-color:#999; width:500px; float:left;">
<div id="dh"  class="gs" >触发动画</div>
</div>
<div class="xs"></div>
</body>
</html>
时间: 2024-08-10 05:12:35

jquery 滚动到指定位置触发动画的相关文章

scroll 滚动到指定位置触发事件 and 点击一按钮/链接让页面定位在指定的位置

scroll 滚动到指定位置触发事件:$(function(){ $(window).scroll(function() { var s =$(window).scrollTop(); if (s>=782) {//782是导航条离页面顶部的距离(px) $('.nav').addClass('fixednav'); } else{ $('.nav').removeClass('fixednav'); } });}); .fixednav{ position:fixed; top:0px; le

监听页面滚动及滚动到指定位置

两种监听页面滚动的方法 一.原生js通过window.onscroll监听window.onscroll = function() {//为了保证兼容性,这里取两个值,哪个有值取哪一个//scrollTop就是触发滚轮事件时滚轮的高度var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;console.log("滚动距离" + scrollTop);} 二.Jquery通过$(wind

IOS学习之UITableView滚动到指定位置

IOS学习之UITableView滚动到指定位置 方法很简单: - (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated 有些需要注意的地方: 如果在reloadData后需要立即获取tableview的cell.高度,或者需要滚动tableview,那么,直接在reloadDa

js将滚动条滚动到指定位置的方法

代码如下(主要是通过设置Location的hash属性): <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <

js滚动到指定位置导航栏固定顶部

<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>js滚动到指定位置导航栏固定顶部</title> <style type="text/css"> body{height: 2500px; margin: 0; padding: 0;} .banner{height: 250px; width: 100%; bac

微信小程序点击滚动到指定位置

公司项目要做一个类似微信通讯录导航的效果,点击右侧字母页面滚动到相应位置. 因为微信小程序没有dom概念,所以不能使用锚点,也不能直接获取对应字母相对页面的偏移位置.此时只能使用小程序创建对象实例的API获取节点信息: let query = wx.createSelectorQuery().in(this); query.selectViewport().scrollOffset() query.select("#Nav").boundingClientRect(); query.s

js 页面滚动到指定位置

项目中,本来想通过点击左侧列表让页面进行快速导航(根据 id="item" 和 a标签的 href 属性[<a href="#item"></a>]),不过滚动后的页面一直是顶在浏览器页面顶部的,不符合项目需求,所以就通过 js 代码让页面进行指定位置滚动,代码如下: $(".left_nav>ul>li").click(function () { var n = parseInt($(this)[0].id)

DIV内滚动条滚动到指定位置

相对浏览器,将指定div滚到到指定位置,其用法如下: $("html,body").animate({scrollTop: $(obj).offset().top},speed); ps:obj是需要定位的对象,speed是滚动的速度 然而如果需要相对某一个容器(称之div1),将其内部的div2滚动到相对div1的指定位置,用法如下: $("div1").animate({scrollTop: $("div2").position().top}

NGUI 滚动到指定位置

将scroll的位置设置在指定位置处,再设置clipOffset; Vector3 pos=dayScroll.transform.localPosition; pos.y=scrollPostion+originalPosy; dayScroll.transform.localPosition=pos; dayScroll.GetComponent<UIPanel>().clipOffset=new Vector2(0,-scrollPostion);