Hello. How can I make it so that when I click on the pictures, the backgrounds of the block (div) change to the clicked picture?
Here is the diagram:
Please advise. Thanks in advance!!
To be honest, I didnβt understand anything from the βschemeβ, but I allowed myself to guess.
There are pictures on the page, and when you click on this picture, would you like the background of the given diva to change?
something like this ?
I'm not sure that I understood correctly, but if you need a background with this picture to be set by clicking on a picture in a certain block, you just need to do this:
<div id="images"> <img src="1.jpg" /> <img src="2.jpg" /> <img src="3.jpg" /> <img src="4.jpg" /> <img src="5.jpg" /> <img src="6.jpg" /> <img src="7.jpg" /> </div> <div id="blocks"> <div id="div_1"></div> <div id="div_2"></div> <div id="div_3"></div> <div id="div_4"></div> </div> <script> $(function () { $(".images img").click(function(){ $("#div_1").css("background", "url('" + $(this).attr("src") + "') 0 0 no-repeat"); }) }) </script>
He wants to say that there is a block on top located a panel of pictures. Click on the pictures and the entire background of this diva is replaced by this picture. I think there can not do without a script. Alas, I canβt help with anything just html + css.
What if one block were changed when clicking on a certain picture, then:
HTML:
<div id="div_1"></div>//ΠΠ»ΠΎΠΊΠΈ <div id="div_2"></div> <div id="div_3"></div> <div id="div_4"></div> <div class="images">//ΠΠΎΠ½ΡΠ΅ΠΉΠ½Π΅Ρ Ρ ΠΊΠ°ΡΡΠΈΠ½ΠΊΠ°ΠΌΠΈ <img src="source" class="forDiv_1">//ΠΠ°ΡΡΠΈΠ½ΠΊΠΈ Ρ ΠΌΠ΅ΡΠΊΠ°ΠΌΠΈ, Π΄Π»Ρ ΠΏΠ΅ΡΠ²ΠΎΠ³ΠΎ Π±Π»ΠΎΠΊΠ° - forDiv_1 ΠΈ Ρ.Π΄. ΠΠΎΠΆΠ΅ΠΌ ΠΊΠΎΠΏΠΈΠΏΠ°ΡΡΠΈΡΡ ΡΡΠΎΠ»ΡΠΊΠΎ, ΡΡΠΎΠ»ΡΠΊΠΎ Π½Π°Π΄ΠΎ. <img src="source" class="forDiv_2"> <img src="source" class="forDiv_3"> <img src="source" class="forDiv_4"> </div>
Here is jQuery:
$(".images > img").click(function(){//ΠΠΎΠ±ΠΈΡΠ°Π΅ΠΌΡΡ Π΄ΠΎ Π½Π°ΡΠΈΡ
ΠΊΠ°ΡΡΠΈΠ½ΠΎΠΊ Π² ΠΊΠΎΠ½ΡΠ΅ΠΉΠ½Π΅ΡΠ΅ if($(this).attr("class") === "forDiv_1")//ΠΡΠΎΠ²Π΅ΡΡΠ΅ΠΌ, Π΅ΡΠ»ΠΈ ΠΊΠ»ΠΈΠΊΠ½ΡΠ»ΠΈ Π½Π° ΠΊΠ°ΡΡΠΈΠ½ΠΊΡ, ΠΊΠΎΡΠΎΡΠ°Ρ ΠΌΠ΅Π½ΡΠ΅Ρ ΠΏΠ΅ΡΠ²ΡΠΉ Π±Π»ΠΎΠΊ $("#div_1").css("background", "url("+$(this).attr("src")+") 0 0 no-repeat");//ΠΌΠ΅Π½ΡΠ΅ΠΌ Π΅Π³ΠΎ if($(this).attr("class") === "forDiv_2")//ΠΠΎΠ²ΡΠΎΡΡΠ΅ΠΌ Π΄Π»Ρ ΠΊΠ°ΠΆΠ΄ΠΎΠ³ΠΎ Π±Π»ΠΎΠΊΠ° $("#div_2").css("background", "url("+$(this).attr("src")+") 0 0 no-repeat"); if($(this).attr("class") === "forDiv_3") $("#div_3").css("background", "url("+$(this).attr("src")+") 0 0 no-repeat"); if($(this).attr("class") === "forDiv_4") $("#div_4").css("background", "url("+$(this).attr("src")+") 0 0 no-repeat"); });
Source: https://ru.stackoverflow.com/questions/143566/
All Articles