Giter Club home page Giter Club logo

blog's People

Contributors

warrenhewitt avatar

Stargazers

陈云 avatar Terry Su 苏溪云 avatar 辰月云冰 avatar  avatar

Watchers

James Cloos avatar  avatar

Forkers

kule2018

blog's Issues

vue配置sass

版本

  • webpack 3.6.0
  • vue 2.5.2
  • sass-loader 6.0.6
  • node-sass 4.7.2

安装

  • npm | cnpm install node-sass --save-dev
  • npm | cnpm install sass-loader --save-dev

webpack.base.config.js

不用修改任何配置

vue文件中使用

<script>
 //直接用js引入样式文件  
 import 'url...';
 </script>
<style type="text/scss" lang="scss">
	如果要引入文件
   @import 'url...';**注意分号必须要加**
</style>

内容自动上下循环滚动JS实现

CSS

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
}

HTML

<div class="roll-box">
    <ul id="roll">
    </ul>
</div>

JS

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);
    }
})()

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.