? about DOM Scripting for a particular project
I was wondering if I could get a little bit of guidance with Javascript. This is all going to be from scratch so no frameworks or plug-ins involved.
I'm starting a new project where I'll have a page with 12 thumbs and a next button. Clicking the next button, slides the 12 thumbs to the left and hides them, showing 12 more thumbs which will be added to the DOM on the fly, etc etc. Once you're on page 2 or above, a previous button will be displayed. All of the info that will be used to populate the DOM I imagine will be in the form of JSON. Is that the best way? Would an array suffice? What is the best way to keep track of what page I'm on? When I'm on page 2, what is the best way to get items 13-24 from the JSON object, etc?
I have some ideas but I'm looking 开发者_运维技巧for best practices.
Use objects inside an array, with each object containing the info such as thumb path, image path, caption, etc.
You can slice()
an array.
However, if using JSON, you probably want to request with XHR the images as you want them, so just pass the page number and your server side code can calculate the offsets.
精彩评论