aralejs / sticky Goto Github PK
View Code? Open in Web Editor NEW实现元素跟随滚动的效果
Home Page: http://aralejs.org/sticky
实现元素跟随滚动的效果
Home Page: http://aralejs.org/sticky
'sticky': 'arale/sticky/1.1.0/sticky',
$('
从实际使用来看,之前在 #4 中提到的占位元素避免影响页面元素的想法还是有必要的。
从实现的角度,clone 不可取,但是可以生造一个空的 div 来代替现有元素。
sticky.stick 接口, 之前采用事件的方式将 stick 和 restored 的时间点暴露给使用者, 但这需要先绑定事件再 render 对象, 接口不太简洁. 在小组讨论后, 将原先方式:
sticky.stick("#stick", 30).on("stick", function(e) {
seajs.log("stick");
}).on("restored", function(e) {
seajs.log("restored");
}).render();
改成:
sticky.stick("#stick", 30, function(status) {
if (status) {
seajs.log("stick");
} else {
seajs.log("unstick");
}
});
即, 增加第三个 callback(status) 参数, status 为 true 时, 表示状态变为 stick, status 为 false 时, 表示状态恢复成原先的 unstick 状态.
我现在有个需求:一个fixed的元素始终保持距body底部一定的距离。
我看代码中直接取的offset().top的距离,这样就导致我页面resize的时候,给了bottom值的元素不准确!
建议如果样式中指明了bottom的值,同时没有声明top值得情况下直接用bottom定位不可以吗?这样也不用处理resize事件,同时也跟使用者的意图是最一致的。
position : sticky
了,考虑可以用原生实现设置了position
参数(小于0),在支持sticky的浏览器中,会连续处罚两次 指定的回调。
主要是 appendChild 的操作,在 IE 下多测试下。
http://www.cnblogs.com/echovalley/archive/2012/12/08/2808232.html
应用场景是这样的:右侧的“狗皮膏药”最开始是static,滚动一定值后变成fixed,继续滚动到一定值(和左侧某元素对齐)后原地变成static
例子:http://sourcing.alibaba.com/buyermarket/buyer_market_list.htm?categoryIds=1509&tracelog=rec_browsing (右侧表单)
其他浏览器或IE9的其他模式都是正常的。
现象描述:
1,页面高度超过浏览器可视区域,将页面滚动到底部,通过Sticky.sticky指定的元素以 position: fixed; 方式浮动在固定位置。
2,动态修改页面内容,使其高度小于可视区域,竖向滚动条消失,通过Sticky.sticky指定的元素仍以 position: fixed; 方式浮动在固定位置。未触发回调方法。
3,更换其他浏览器或IE9的其他模式则不会浮动。
先记下. 以后再调
另一个例子:
http://leafo.net/sticky-kit/
代码第13和14行:
var isPositionStickySupported = checkPositionStickySupported(),
isPositionFixedSupported = checkPositionFixedSupported();
这两个变量是否多余呢?代码中其他部分并没有用到。而且如果这样做了,我用checkPositionStickySupported()直接判断不是比再声明isPositionStickySupported更方便?!
官网的例子就有这个问题,当浏览器 resize 时 top 元素 没问题 就 bottom 元素会消失!
从代码上看,考虑的情况太少了,在实际应用中会碰到很多问题。比如窗口高度小于fix内容,宽度小于页面宽度,。。。。。等等
现在是在 Sticky 调用时记录了 offsetTop ,但是如果后续由于页面元素高度变化,会导致记录的 originTop 的值不准确。
之前 使用 timer 100ms, 不太好, 尝试了下以下的 a.className = a.className. 还是闪的厉害.
https://github.com/lifesinger/lifesinger.github.com/blob/master/lab/2009/ie6_fixed_position_v2.html
在IE6下,使用鼠标滚轮,页面可以无限往下滚(出现的概率比较小),
另外,在IE6下滚动页面的时候有很严重的闪屏现象。
https://my.alipay.com/portal/home.htm
新版我的支付宝首页底部的生活助手栏
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.