There is a code that changes css by clicking on the button, but when you refresh the css page, it is natural to become the same. Is it possible to save a change to a file? Just as far as I know, js does not work with files, then is it possible using php to get data about pressing a button, and then write to a file?
- Tell me exactly what exactly you need ... your specific task ... maybe it can be solved in another way ... - oneboy
- There is a js code: <script> $ (window) .load (function () {$ ("# social"). Click (function () {$ ("# image"). Animate ({marginLeft: ".1%" }, 1500);});}); </ script> it is necessary that the margin-left change be recorded in the index.html file in the <style> </ style> tag, and when you click on the button, it was not just ".1%" a "(Value that already exists +. 1% " - phan
- oneIMHO, Ajax + session. A class name is better to change. - zenith
- How can this be implemented? - phan
|
1 answer
$(function() { var img = $('#image'); img.css('margin-left', localStorage.getItem('image-pos') || 0); $('#social').click(function(e) { img.animate({'margin-left': '+=50px'}, 1500, function() { localStorage.setItem('image-pos', img.css('margin-left')); }); }); });
If you need support for old browsers, you can save in a cookie or session.
- I did this: $ (function () {var img = $ ('# image'); img.css ('margin-left', localeStorage.getItem ('image-pos') || 0); $ (' # social ') .click (function (e) {img.animate ({marginLeft: "20%"}, 1500, function () {localeStorage.setItem (' image-pos', img.css ('margin-left')) ;});});}); does not work, what could be the error? - phan
- Corrected, should now work. - Vadym Petrychenko
|