autojs怎么上滑屏幕

JavaScript06

autojs怎么上滑屏幕,第1张

首先设定屏幕的宽和高

var height = device.height//设定高度值=设备高度

var width = device.width//设定宽度值=设备宽度

setScreenMetrics(width, height)//设置脚本坐标点击所适合的屏幕宽高。如果脚本运行时,屏幕宽度不一致会自动放缩坐标。

然后下面的代码是上划

swipe(width / 2, height - 500, width / 2, 0, 500)

语句解析:

swipe(起点横坐标,起点纵坐标,终点横坐标,终点纵坐标,使用时间)

代码解析:

width / 2是宽度二分之一处。也就是屏幕宽度的中间位置。

height - 500是高度减500像素,屏幕顶部为0。

0是屏幕顶端。

500是手指从起点移动到终点所需时间,单位是毫秒。

这样讲,应该很明白了。

如果需要下滑,那么将起点坐标设置到屏幕下方,终点坐标设置到屏幕顶端即可。

jQuery监听鼠标滚轮(滚动)事件

第一步:下载jquery-mousewheel插件

第二步:复制以下代码做测试,打开日志看效果

jQuery(function($) {

$('#nav')

.bind('mousewheel', function(event, delta) {

var dir = delta >0 ? 'Up' : 'Down'

if (dir == 'Up') {

console.log(“向上滚动, www.imiansha.com”)

} else {

console.log(“向下滚动, http: //blog.csdn.net/u011627980”)

}

return false

})

})

}

js实现随页面滑动效果的方法。具体如下:

页面向上向下滚动,分享到的模块随着滑动。

要点:

代码如下:

var scrtop =document.documentElement.scrollTop||document.body.scrollTop

var height = document.documentElement.clientHeight||document.body.clientHeight

var top = scrtop + (height - jb51.offsetHeight)/2

top = parseInt(top)

获得页面垂直居中的位置

上代码:

<!DOCTYPE html>

<html>

<head>

<meta charset="gb2312" />

<title>无标题文档</title>

<style>

body{margin:0padding:0font:12px/1.5 arialheight:2000px}

#jb51{width:100pxheight:200pxline-height:200px

text-align:centerborder:1p solid #ccc

background:#f5f5f5position:absoluteleft:-100pxtop:0}

#jb51_tit{position:absoluteright:-20pxtop:60px

width:20pxheight:60pxpadding:10px 0

background:#06ctext-align:center

line-height:18pxcolor:#fff}

</style>

<script>

window.onload = function(){

var jb51 = document.getElementById("jb51")

jb51.onmouseover = function(){

startrun(jb51,0,"left")

}

jb51.onmouseout = function(){

startrun(jb51,-100,"left")

}

window.onscroll = window.onresize = function(){

var scrtop=document.documentElement.scrollTop||document.body.scrollTop

var height=document.documentElement.clientHeight||document.body.clientHeight

var top = scrtop + (height - jb51.offsetHeight)/2

top = parseInt(top)

startrun(jb51,top,"top")

}

}

var timer = null

function startrun(obj,target,direction){

clearInterval(timer)

timer = setInterval(function(){

var speed = 0

if(direction == "left"){

speed = (target-obj.offsetLeft)/8

speed = speed>0?Math.ceil(speed):Math.floor(speed)

if(obj.offsetLeft == target){

clearInterval(timer)

}else{

obj.style.left = obj.offsetLeft + speed + "px"

}

}

if(direction == "top"){

speed = (target-obj.offsetTop)/8

speed = speed>0?Math.ceil(speed):Math.floor(speed)

if(obj.offsetTop == target){

clearInterval(timer)

}else{

obj.style.top = obj.offsetTop + speed + "px"

}

document.title = obj.offsetTop + ',' + target + ',' +speed

}

},30)

}

</script>

</head>

<body>

<div id="jb51">

分享到内容

<span id="jb51_tit">分享到</span>

</div>

</body>

</html>