-5

I have in my website, some javascript code that is responsible for the scrolling in the site.

I want to create trigger button so the users can enable/disable it.

<script src="/plugins/js/somejs1.js"></script>
<script src="/plugins/js/somejs2.js"></script>
<script type="text/javascript">
    // some js (the code i want make a trigger button)
</script>
<span type="checkbox" id="the1" checked>
 Display/Hide Button
</span>
<div id="trigger1">
 Text Text Text
</div>

Can it be done with PHP ?

Subin
  • 3,445
  • 1
  • 34
  • 63
Darksane
  • 1
  • 1
  • 3
    PHP runs server-side. Javascript runs client-side. You'll want to run some javascript function upon clicking the "trigger button". – Patrick Q Mar 18 '14 at 17:48
  • You don't need PHP for that. PHP simply outputs HTML/JS. A button to enable or disable that would be pure JS. – NullUserException Mar 18 '14 at 17:49
  • No, it cannot be done with php. Yes, you can do it with javascript, but it will depend on what the "some javascript code" does. – Kevin B Mar 18 '14 at 17:49
  • Also, technically it could be done with PHP.. you could send a GET flag to not include JS files, which would, in effect, disable the javascript on the site. A session variable could be used to remember this request for the user, and then could be turned back on using another GET parameter in the request.. – RaggaMuffin-420 Mar 18 '14 at 17:52
  • @RaggaMuffin-420 But then each enabling/disabling action would require a reload of the page (or at least parts of the page), which is completely unnecessary. – NullUserException Mar 18 '14 at 17:54
  • im using jquery infinite scrolling. http://www.jquery4u.com/tutorials/jquery-infinite-scrolling-demos/ – Darksane Mar 18 '14 at 17:54
  • @Darksane Infinite scrolling is terrible from a UX perspective ([relevant xkcd](https://xkcd.com/1309/)). I would seriously think about whether or not it's really necessary before using this "feature" in the first place. – NullUserException Mar 18 '14 at 17:57
  • @NullUserException I just said it was possible.. not preferred... – RaggaMuffin-420 Mar 18 '14 at 17:57

1 Answers1

0

part one:

to do it purely with javascript:

try saving a cookie with a true/false value to keep the scrollingEnabled value, and then using a regular button change it from true to false and vice versa accordingly

to do it with php: print an element with an attribute or inner text 'true' / 'false' or set a cookie.

part two

in that scrolling function first check the cookie or your custom element and execute the function's code according to the value u have.

Banana
  • 7,424
  • 3
  • 22
  • 43