Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> jquery szerokość / wysokość obrazka różne style
marcus755
post 9.09.2014, 10:45:35
Post #1





Grupa: Zarejestrowani
Postów: 158
Pomógł: 1
Dołączył: 6.12.2012

Ostrzeżenie: (0%)
-----


Jeśli szerokość obrazka większa niż wysokość, to jakiś styl,
jeśli wysokość obrazka większa niż szeokość, to jakiś inny styl,
jak zrobić?
co z poniższym kodem jest nie tak, że nie działa?
jak go zapisać prościej?

  1.  
  2. $(document).ready(function(){
  3.  
  4. var theHeight = $(".image img").height() > $(".image img").width();
  5. var theWidth = $(".image img").height() < $(".image img").width();
  6. alert(theHeight);
  7.  
  8. if ($(".image img") == theHeight) {
  9. $(this).css({"border":"0px #000 solid"});
  10. }
  11. if ($(".image img") == theWidth) {
  12. $(this).css({"border":"3px #000 solid"});
  13. }
  14. });
  15.  


Ten post edytował marcus755 9.09.2014, 10:52:00
Go to the top of the page
+Quote Post
Turson
post 9.09.2014, 10:47:39
Post #2





Grupa: Zarejestrowani
Postów: 4 291
Pomógł: 829
Dołączył: 14.02.2009
Skąd: łódź

Ostrzeżenie: (0%)
-----


Co jest nie tak?
nie $(.image img) a $('.image img') lub $(".image img")
we wszystkich przypadkach. Zobacz na kolorowanie składni jak się wysypało... Korzystaj z przeglądarkowej konsoli javascript to może uratuje życie
Go to the top of the page
+Quote Post
marcus755
post 9.09.2014, 10:54:55
Post #3





Grupa: Zarejestrowani
Postów: 158
Pomógł: 1
Dołączył: 6.12.2012

Ostrzeżenie: (0%)
-----


co jeszcze, poza cudzysłowami, których brak zauważyłem w międzyczasie;-)
Go to the top of the page
+Quote Post
Turson
post 9.09.2014, 11:02:09
Post #4





Grupa: Zarejestrowani
Postów: 4 291
Pomógł: 829
Dołączył: 14.02.2009
Skąd: łódź

Ostrzeżenie: (0%)
-----


nie $(this).css({"border":"3px #000 solid"}); a $(this).css({"border","3px solid #000"});

Ten post edytował Turson 9.09.2014, 11:02:26
Go to the top of the page
+Quote Post
marcus755
post 9.09.2014, 11:06:09
Post #5





Grupa: Zarejestrowani
Postów: 158
Pomógł: 1
Dołączył: 6.12.2012

Ostrzeżenie: (0%)
-----


co jeszcze?:-)
Go to the top of the page
+Quote Post
Turson
post 9.09.2014, 11:07:53
Post #6





Grupa: Zarejestrowani
Postów: 4 291
Pomógł: 829
Dołączył: 14.02.2009
Skąd: łódź

Ostrzeżenie: (0%)
-----


Generalnie to jest pozbawione logiki.
Pobierasz wysokość '.image img' a potem przyrównujesz '.image img' to tej zmiennej.
Go to the top of the page
+Quote Post
trueblue
post 9.09.2014, 11:09:13
Post #7





Grupa: Zarejestrowani
Postów: 6 799
Pomógł: 1827
Dołączył: 11.03.2014

Ostrzeżenie: (0%)
-----


Może być ":" jeśli przekazujesz jako obiekt, jeśli ",", to css("border","3px solid #000");

Co to za wygibasy?
  1. if ($(".image img") == theHeight) {


Ten post edytował trueblue 9.09.2014, 11:09:29


--------------------
Go to the top of the page
+Quote Post
marcus755
post 9.09.2014, 11:26:37
Post #8





Grupa: Zarejestrowani
Postów: 158
Pomógł: 1
Dołączył: 6.12.2012

Ostrzeżenie: (0%)
-----


co dalej?
Go to the top of the page
+Quote Post
trueblue
post 9.09.2014, 11:29:16
Post #9





Grupa: Zarejestrowani
Postów: 6 799
Pomógł: 1827
Dołączył: 11.03.2014

Ostrzeżenie: (0%)
-----


Pokaż kod.


--------------------
Go to the top of the page
+Quote Post
Turson
post 9.09.2014, 11:30:33
Post #10





Grupa: Zarejestrowani
Postów: 4 291
Pomógł: 829
Dołączył: 14.02.2009
Skąd: łódź

Ostrzeżenie: (0%)
-----


Co dalej? Wysil się i przeanalizuj samodzielnie kod a nie bezsensu zadajesz takie pytania nie podając nawet kodu łaskawie...
Go to the top of the page
+Quote Post
marcus755
post 9.09.2014, 12:17:17
Post #11





Grupa: Zarejestrowani
Postów: 158
Pomógł: 1
Dołączył: 6.12.2012

Ostrzeżenie: (0%)
-----


http://jsfiddle.net/2owexpsh/
Go to the top of the page
+Quote Post
Turson
post 9.09.2014, 12:29:14
Post #12





Grupa: Zarejestrowani
Postów: 4 291
Pomógł: 829
Dołączył: 14.02.2009
Skąd: łódź

Ostrzeżenie: (0%)
-----


Zacznij czytać dokładnie to co piszemy
if ($(".image img") == theHeight) {
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 14.06.2025 - 01:38