0

I'm using jquery cont.scrollLeft(value) which moves the scrollbar and triggers the scroll event, but I also need to add an event parameter so I would be able to identify in the event handler that this scroll was done by my code.

is it possible or maybe there's another way to do scrollLeft(val) and trigger the event so that I could add a flag that would be accessible from the event parameter

1 Answer 1

1

Any problems with this approach?

var Scrool="user";

$("div.demo").scroll(function() {
  console.clear();
  if (Scrool==="code") {
  console.log("code scrolled")
  }else if (Scrool==="user"){
  console.log("user scrolled")
  }
  
});
$("#target").click(function() {
  $("div.demo").scrollLeft(300);
  Scrool="code";
});
div.demo {
  background: #ccc none repeat scroll 0 0;
  border: 3px solid #666;
  margin: 5px;
  padding: 5px;
  position: relative;
  width: 200px;
  height: 100px;
  overflow: auto;
}

p {
  margin: 10px;
  padding: 5px;
  border: 2px solid #666;
  width: 1000px;
  height: 1000px;
}
<!doctype html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <title>scrollLeft demo</title>

  <script src="https://code.jquery.com/jquery-3.5.0.js"></script>
</head>

<body>

  <div class="demo">
    <h1>lalala</h1>
    <p>Hello</p>
  </div>

  <button id="target">Click me</button>
</body>

</html>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.