When clicking on which type, the distance between this dom and the left side of the parent dom can be calculated. The width of the screen can be calculated. Compare the distance of the dom with the half width of the screen, and then make a judgment. When to move and how far to move
When clicking Military, get the distance between the military dom and the left side of the parent dom, divide the distance by 2, and then move it
If you click the one on the far left and center it, wouldn’t the left side be blank?
When clicking on which type, the distance between this dom and the left side of the parent dom can be calculated.
The width of the screen can be calculated.
Compare the distance of the dom with the half width of the screen, and then make a judgment. When to move and how far to move
margin-left:-(x * this.index)px;
Determine the index of the currently clicked object and then calculate the offset
I just did this demo test yesterday. The layout of Unexpected Encounter is also the same as Toutiao.
JQ implementation method:
html
css
jq