JSFiddle - React, Tailwind, and code Playground

by Stéphane LEGRAND

HTML

<div id="map">
  <div class="overlay-city">
    <div class="tile">exemple1</div>
    <div class="tile">exemple2</div>
    <div class="tile">exemple3</div>
    <div class="tile">exemple4</div>
    <div class="tile">exemple5</div>
    <div class="tile">exemple6</div>
    <div class="tile">exemple7</div>
    <div class="tile">exemple8</div>
  </div>
</div>

CSS

div#map {
    background-image: url(http://upload.wikimedia.org/wikipedia/commons/9/91/Flexopecten_ponticus_2008_G1.jpg);
    background-position: 0 0;
    background-repeat: no-repeat;
    background-color: blue;
    border: 1px solid #aaa;
    width: 800px;
    height: 600px;
    margin: 0 auto;
}

JavaScript

$(document).ready(function(){
    var $bg = $('#map'),
   			$oc = $('.overlay-city'),
        elbounds = {
            w: parseInt($bg.width()), 
            h: parseInt($bg.height()),
            ow: parInt($oc.width()),
            oh: parseInt($oc.height())
            
        },
        bounds = {w: 2350 - elbounds.w, h: 1750 - elbounds.h, ow: 2350 - elbounds.ow, oh: 1750 - elbounds.oh},
        origin = {x: 0, y: 0},
        start = {x: 0, y: 0},
        movecontinue = false;
    
    function move (e){
        var inbounds = {x: false, y: false},
            offset = {
                x: start.x - (origin.x - e.clientX), 
                y: start.y - (origin.y - e.clientY)
            };
        
        inbounds.x = offset.x < 0 && (offset.x * -1) < bounds.w;
        inbounds.y = offset.y < 0 && (offset.y * -1) < bounds.h;
        inbounds.x = offset.x < 0 && (offset.x * -1) < bounds.ow;
        inbounds.y = offset.y < 0 && (offset.y * -1) < bounds.oh;
        
        if (movecontinue && inbounds.x && inbounds.y) {
            start.x = offset.x;
            start.y = offset.y;
            
            $(this).css('background-position', start.x + 'px ' + start.y + 'px');
        }
        
        origin.x = e.clientX;
        origin.y = e.clientY;
        
        e.stopPropagation();
        return false;
    }
    
    function handle (e){
        movecontinue = false;
        $bg.unbind('mousemove', move);
        
        if (e.type == 'mousedown') {
            origin.x = e.clientX;
            origin.y = e.clientY;
            movecontinue = true;
            $bg.bind('mousemove', move);
            $oc.bind('mousemove', move);
        } else {
            $(document.body).focus();
        }
        
        e.stopPropagation();
        return false;
    }
    
    function reset (){
        start = {x: 0, y: 0};
        $(this).css('backgroundPosition', '0 200');
    }
    
    $bg.bind('mousedown mouseup mouseleave', handle);
   ...