Round divs in an overflow holder: hidden vertical scroll and horizontal scroll - mousemove

I am trying to make round divs in the owner div. a overflow:hidden;. I am experiencing some problems with the mousemove event. Here is my example: jsFiddle , and that's my goal: ello.co . I also searched for some questions about mousemove, but I could not find vertically and horizontally together. HTML:

<div id="holder"><ul id="scroll">
<li><div class="si"></div></li>
<li><div class="si"></div></li><ul>
<li><div class="si"></div></li><ul>  
</ul>
</ul></div>

CSS

#holder {
    background: pink;
    width: 500px;
    height: 500px;
    overflow:hidden;
    line-height: 30px;
    margin-left: 100px;
}
#scroll{
    height: 30px;
    line-height: 30px;
    margin-left: 0;
    padding: 0 10px;
}
#scroll li {
    float: left;
    padding: 0 5px;
}

.si{
  width:150px;
  height:150px;
  background-color:black;
  float:left;
  border-radius:150px;
  margin:10px;
}
.si:hover{
  width:160px;
  height:160px;
  margin:2px;
}

JavaScript:

var sum = 0;
$("#scroll li").each(function() {
    sum += $(this).width() + parseInt($(this).css('paddingLeft')) + parseInt($(this).css('paddingRight'))
});
$("#scroll").css('width', sum);

$("#holder").mousemove(function(e) {
    x = -(((e.pageX - $('#scroll').position().left) / $("#holder").width()) * ($("#scroll").width() + parseInt($("#scroll").css('paddingLeft')) + parseInt($("#scroll").css('paddingRight')) - $("#holder").width()));

    $("#scroll").css({
        'marginLeft': x + 'px'
    });
});
+4
source share
1 answer

If you want it to move vertically, you can use the same code as for x and adapt it:

http://jsfiddle.net/pAu8Q/511/

y = -(((e.pageY - $('#scroll').position().left) / $("#holder").width()) * ($("#scroll").width() + parseInt($("#scroll").css('paddingTop')) + parseInt($("#scroll").css('paddingBottom')) - $("#holder").width()));

$("#scroll").css({
    'marginTop': y + 'px'
});
+2

Source: https://habr.com/ru/post/1618811/


All Articles