亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

為什么我將鼠標移動上去后他的值不是到400px,而是到391px從而停下來了?

http://img1.sycdn.imooc.com//568b4c8200012a2f09330597.jpg

/**
* Created by Administrator on 2016/1/5.
*/



function setMove(obj,sty,goal){
? ?var div =document.getElementById("wrap");
? ?var timer=null;
? ?timer=setInterval(function(){
? ? ? ?var ist = 0
? ? ? ?if(sty=='opacity'){
? ? ? ? ? ?ist=Math.round(parseFloat(setStyle(obj,sty))*100);
? ? ? ?}else{
? ? ? ? ? ?ist=parseInt(setStyle(obj,sty));
? ? ? ?}

? ? ? ?var speed = (goal-ist)/10;
? ? ? ?speed= speed>0? Math.ceil(speed):Math.floor(speed);
? ? ? ?if(ist == goal){
? ? ? ? ? ?clearInterval(timer);
? ? ? ?}else{
? ? ? ? ? ?if(sty=='opacity'){
? ? ? ? ? ? ? ?obj.style.filter='alpha(opacity'+(ist + speed)+')';
? ? ? ? ? ? ? ?obj.style.opacity=(ist + speed)/100;
? ? ? ? ? ?}else {
? ? ? ? ? ? ? ?obj.style[sty] = ist + speed + "px";
? ? ? ? ? ?}
? ? ? ?}
? ?},30);
}

function setStyle(obj,attr){
? ?if(obj.currentStyle){
? ? ? ?return obj.currentStyle[attr];
? ?}else{
? ? ? ?return getComputedStyle(obj,false)[attr];
? ?}
}

正在回答

1 回答

<html>
<head>
????<title>?事件</title>
????<meta?charset="utf-8">
????<title>111111111</title>
????<style>
????????*{
????????????margin:?0;
????????????padding:?0;
????????}

????????div{
????????????width:?200px;
????????????height:?200px;
????????????background-color:?#0B5DE5;
????????}
????</style>
????<script>
????????function?setMove(obj,sty,goal){
????????????var?div?=document.getElementById("wrap");
????????????var?timer=null;
????????????timer=setInterval(function(){
????????????????var?ist?=?0
????????????????if(sty=='opacity'){
????????????????????ist=Math.round(parseFloat(setStyle(obj,sty))*100);
????????????????}else{
????????????????????ist=parseInt(setStyle(obj,sty));
????????????????}

????????????????var?speed?=?(goal-ist)/10;
????????????????speed=?speed>0??Math.ceil(speed):Math.floor(speed);
????????????????if(ist?==?goal){
????????????????????clearInterval(timer);
????????????????}else{
????????????????????if(sty=='opacity'){
????????????????????????obj.style.filter='alpha(opacity'+(ist?+?speed)+')';
????????????????????????obj.style.opacity=(ist?+?speed)/100;
????????????????????}else?{
????????????????????????obj.style[sty]?=?ist?+?speed?+?"px";
????????????????????}
????????????????}
????????????},30);
????????}

????????function?setStyle(obj,attr){
????????????if(obj.currentStyle){
????????????????return?obj.currentStyle[attr];
????????????}else{
????????????????return?getComputedStyle(obj,false)[attr];
????????????}
????????}
????</script>
</head>
<body>
<div?id="div"></div>
<script>
????var?div?=?document.getElementById('div');
????div.onmouseover?=?function(){
????????setMove(this,'width',400);
????}
</script>
</body>
</html>

是400呀。

0 回復 有任何疑惑可以回復我~
#1

蛋疼少年的和諧青春 提問者

我在Chrome瀏覽器上面運行到不了400, 但是用Firefox 就能運行成功到達400,請問下大俠,這個是什么樣的一個問題,就是您是用的那款瀏覽器做的測試呢?
2016-01-05 回復 有任何疑惑可以回復我~
#2

李曉健 回復 蛋疼少年的和諧青春 提問者

我用的就是chrome
2016-01-06 回復 有任何疑惑可以回復我~
#3

蛋疼少年的和諧青春 提問者 回復 李曉健

我的還是出問題。。
2016-01-08 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

為什么我將鼠標移動上去后他的值不是到400px,而是到391px從而停下來了?

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號