Je souhaite tracer un quadrillage de fréquence variable au-dessus d'une image statique dans jquery, des suggestions quant à l'approche la meilleure/la plus simple - merci!jQuery manipulation d'image
2
A
Répondre
1
Voici un mockup très rapide qui devrait aider à vous donner une idée de mon prendre
var top = image.top;
var left = image.left;
var width = image.width;
var height = image.height;
var boxHeight = 10; //change this how tall you want each grid box to be
var boxWidth = 10; //same for width
gridtop = top;
gridleft = left;
while (gridtop < top + height); {
gridtop += boxHeight;
$('body').append('<div></div>').css('position', 'absolute').css('width', width).css('top', gridtop).css('left', left);
}
while (gridleft < left + width); {
gridleft += boxWidth;
$('body').append('<div></div>').css('position', 'absolute').css('height', height).css('left', gridleft).css('top', top);
}
1
// Specify the number of boxes
var verticalBoxes = 10;
var horizontalBoxes = 10;
var countBoxes = verticalBoxes*horizontalBoxes;
var imageHeight = img.height();
var imageWidth = img.width();
var boxHeight = imageHeight/verticalBoxes;
var boxWidth = imageWidth/horizontalBoxes;
// #grid needs to be relatively positioned
var grid = $('#grid').detach();
for(i = 0; i < countBoxes ; i++){
grid.append('<div class=\'boxes\'></div>');
}
// This is the absolutely positioned container overlaying the image
$('#grid-container').append(grid);
$('head').append('<style>.boxes {outline:1px solid black; height:'+boxHeight+'px; width:'+boxWidth+'px; float:left; }</style>');
Je crois que cette version est plus performante, repose sur le modèle de boîte CSS plutôt que de placer chaque boîte individuellement. Cependant, il spécifie le nombre de boîtes plutôt que la taille de la boîte ...
Questions connexes
- 1. cours Manipulation avec jquery
- 2. jQuery tableau JavaScript manipulation
- 3. Manipulation d'attributs JQuery
- 4. jQuery DOM manipulation
- 5. jQuery Html Manipulation Question
- 6. Manipulation de chaîne jQuery
- 7. Annuler événement jQuery manipulation
- 8. jQuery Table manipulation
- 9. Manipulation de chaînes dans jQuery
- 10. Javascript/manipulation de chaîne jQuery?
- 11. erreurs de manipulation jQuery .ajax
- 12. Manipulation du focus d'entrée JQuery
- 13. jQuery + CSS Manipulation using each()
- 14. Rails avec manipulation JQuery DIV
- 15. Manipulation DOM XHTML avec jQuery
- 16. Manipulation de chaînes dans jQuery
- 17. Manipulation d'une variable contenant XML avec jQuery?
- 18. manipulation des cases à cocher Jquery aide
- 19. Manipulation de la table en utilisant Jquery
- 20. La manipulation d'image avec JQuery et PHP
- 21. Manipulation d'éléments de liste avec jQuery
- 22. manipulation des cases à cocher jQuery
- 23. Manipulation de table HTML en utilisant jQuery
- 24. jQuery manipulation de nom de fichier
- 25. jQuery indexSi manipulation de boîtes de sélection
- 26. Manipulation Spring MVC forme: radiobutton avec Jquery
- 27. Manipulation d'une table avec JavaScript/jQuery
- 28. La manipulation d'attribut jquery (manipulation DOM) pour le texte de type d'entrée ne fonctionne pas?
- 29. Table de manipulation
- 30. Silverlight & Visual Tree Manipulation