Skip to content

📋 Javascript30 tutorial 27 of 30 to click and drag on a html page

Notifications You must be signed in to change notification settings

AndrewJBateman/javascript-click-drag

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

⚡ Javascript Click Drag

GitHub repo size GitHub pull requests GitHub Repo stars GitHub last commit

📄 Table of contents

📚 General info

  • Tutorial Code to scroll horizontally using click and drag.

📷 Screenshots

Example screenshot.

📶 Technologies

💾 Setup

  • Open index.html in browser. If any code is changed the browser needs to be refreshed.

💻 Code Examples

  • calculate slider scroll left value from cursor position
slider.addEventListener('mousemove', (e) => {
  if (!isDown) return; //stop the function from running
  console.log(isDown);
  e.preventDefault(); // prevent selection of text etc inside area.
  const x = e.pageX - slider.offsetLeft;
  const scrollMultiple = 3; // scroll 3 pixels for each pixel moved by the mouse.
  const walk = (x - startX)*scrollMultiple;
  slider.scrollLeft = scrollLeft - walk;
  console.log('slider scrollleft', slider.scrollLeft); //max value 4207.2001953125
});

🆒 Features

  • Scroll speed can be changed.

📋 Status & To-Do List

  • Status: Working
  • To-Do: Nothing

👏 Inspiration

📁 License

  • This project is licensed under the terms of the MIT license.

✉️ Contact

About

📋 Javascript30 tutorial 27 of 30 to click and drag on a html page

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published