Giter Site home page Giter Site logo

fly's Issues

在手机web页面中:top值问题

如果商品很多,页面可以滚动,当商品开始时的top值高度大于屏幕的高度,加入购物车时,top值会比商品在屏幕中显示的位置低,请问如何解决?谢谢

is bug?

today we find our project not work,and the github`s demo is bad ,is auther still service

能解释下这段代码原理和作用么?

var distance = Math.sqrt(Math.pow(start.top - end.top, 2) + Math.pow(start.left - end.left, 2)),
        // 元素移动次数
        steps = Math.ceil(Math.min(Math.max(Math.log(distance) / 0.05 - 75, 30), 100) / settings.speed),
        ratio = start.top == vertex_top ? 0 : -Math.sqrt((end.top - vertex_top) / (start.top - vertex_top)),
        vertex_left = (ratio * start.left - end.left) / (ratio - 1),

特别是这里的steps

加入购物车时页面会自动滚到顶部

如题,不知道该怎么解决
我的代码

$(".addcar").click(function(event){ 
 	var offset = $("#end").offset(); 
     var addcar = $(this); 
     var img = addcar.parent().find('img').attr('src'); 
     var flyer = $('<img class="u-flyer" src="'+img+'">'); 
     $ (window).unbind ('scroll');
     flyer.fly({ 
         start: { 
             left: event.pageX, //开始位置(必填)#fly元素会被设置成position: fixed 
             top: event.pageY //开始位置(必填) 
         }, 
         end: { 
             left: offset.left+10, //结束位置(必填) 
             top: offset.top+10, //结束位置(必填) 
             width: 0, //结束时宽度 
             height: 0 //结束时高度 
         }, 
         onEnd: function(){ //结束回调 
             $("#msg").show().animate({width: '250px'}, 200).fadeOut(1000); //提示信息 
 			
         } 
     }); 
 }); 

乱点出一个bug

readme中的demo:
image

一直点购物车点的下面,结果成这样了。

解决Demo中一个BUG,图标错乱,不知道算不算BUG。

bug问题:当有滚动条的时候,飞车进入购物车。不是购物车图标的位置。
原因:貌似源代码没有考虑滚动条的情况吧,当有滚定条的时候,需要#end的顶部距离减去滚动条的距离。这样有滚动条的时候,商品也能飞入到右侧的购物车的位置。

解决方案:

$('html,body').on('click', addProduct);
function addProduct(event){
var offset = $("#end").offset(),
var scrollX=$(window).scrollTop(); //获取滚动条的距离。
flyer = $('');
if(scrollX==0) //判断滚动条的距离变化,如果没有变化
{
flyer.fly({
start: {
left: event.pageX,
top: event.pageY
},
end: {
left: offset.left,
top: offset.top,
width: 20,height: 20
}
});
}
else
{
flyer.fly({
start: {
left: event.pageX,
top: event.pageY-scrollX //这里也要,当有滚动条的时候,点击的时候,img飞出的起始位置不是点击的位置。
},
end: {
left: offset.left,
top: offset.top-scrollX, //#end 的顶部距离减去滚动条的距离
width: 20,height: 20
}
});
}
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.