warrenhewitt / blog Goto Github PK
View Code? Open in Web Editor NEWblogs and note ......
Home Page: https://warrenhewitt.github.io/blog/
blogs and note ......
Home Page: https://warrenhewitt.github.io/blog/
不用修改任何配置
<script>
//直接用js引入样式文件
import 'url...';
</script>
<style type="text/scss" lang="scss">
如果要引入文件
@import 'url...';**注意分号必须要加**
</style>
ul,li { padding: 0; margin: 0 }
.roll-box {
height: 400px;
background: #007acc;
overflow: hidden;
color: #fff;
}
#roll li {
height: 25px;
border-bottom: 1px solid #ddd
}
<div class="roll-box">
<ul id="roll">
</ul>
</div>
function getData() {
var htmlStr = '';
for (var i = 0; i < 20; i++) {
htmlStr += '<li id="i-' + i + '">' + 'this is ' + i + '</li>'
}
return htmlStr;
}
(function roll() {
var UL_HEIGHT = 400, SPEED = 40, LI_HEIGHT = 25;
var ulObj = document.getElementById('roll');
ulObj.innerHTML = getData();
var height = ulObj.offsetHeight;
var move = 0;
var clearIn = '', mouseOut = true;
// 添加鼠标操作相关事件
ulObj.addEventListener('mouseenter',function(){
mouseOut = false
});
ulObj.addEventListener('mouseleave',function(){
mouseOut = true
animationRoll()
});
ulObj.addEventListener('click',function(e){
if(e.target.nodeName === 'LI') {
alert('id is:' + e.target.id)
}
});
// 滚动步骤1.将外部ul移动一个li的高度的距离 2.将移出的li元素放到最后,实现循环,并复原ul的移动距离。
function animationRoll() {
clearIn = setInterval(function () {
if(mouseOut){
move++;
ulObj.setAttribute('style', 'margin-top:-' + move + 'px');
if (move === LI_HEIGHT) {
move = 0;
ulObj.setAttribute('style', 'margin-top:-' + move + 'px');
var temp = ulObj.children[0];
ulObj.removeChild(temp)
ulObj.appendChild(temp)
}
} else {
clearInterval(clearIn);
}
}, SPEED)
}
if (height > UL_HEIGHT) {
diffrence = height - UL_HEIGHT
animationRoll()
} else {
console.log(ulObj.offsetHeight);
}
})()
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.