Mostrando entradas con la etiqueta jquery. Mostrar todas las entradas
Mostrando entradas con la etiqueta jquery. Mostrar todas las entradas
martes, 19 de abril de 2016
jquery $ is not defined in angularjs
Este mensaje me ha dado muchos dolores de cabeza en angularJS y tampoco he encontrado solución por ningún foro o ayuda. Expongo mi experiencia por si ha alguien le es útil.
EL objetivo era intentar usar el plugin de Jquery owl-carousel en un proyecto con Angular JS donde obtendriamos la información a mostrar en el owl de forma asíncrona mediante promesas en servicios de angularJS ("peticiones ajax").
Al usar el proyecto en un servidor apache funciona correctamente. Al visualizar el proyecto mediante el motor de ionic con el comando "ionic serve" lanza el error "$ is not defined in angularjs" por la consola y no es capaz de generar correctamente el slider.
El motivo es que el script de ionic.bundle "bloquea" los scripts durante el desarrollo como indica en el comentario por defecto que anuncia:
Si intentamos visualizar el contenido del jquery.js en la consola de desarrollador de chrome, pestaña de sources. Vemos que no muestra contenido. Ni es capaz de ejecutar setencias de jquery en la consola.
Para solucionarlo basta modificar las importaciones locales por recursos no locales: Ejemplo:
jueves, 8 de octubre de 2015
Código de ejemplo para prettyPhoto
prettyPhoto Example
A gallery that does more than images
Introduction
All examples and code modified from: http://www.no-margin-for-errors.com/projects/prettyphoto-jquery-lightbox-clone/
Lightbox is a common way to easily create an image gallery. Lightbox used to use two JavaScript libraries named Prototype and Scriptaculous. These are both good. HoweverjQuery seems to be the dominant library. Lightbox has recently switched to jQuery.
Even so it doesn't have some of the capabilities to show many different kinds of content (like video or whatever). I'm showing you how to do a similar thing with prettyPhoto which is also some JavaScript built on top of the jQuery library. Once you have the jQuery library installed in your site you will have a lot of other options to add other interactivity to your site. There are literally thousands of tutorials and extensions for jQuery.
- http://docs.jquery.com/Tutorials
- http://net.tutsplus.com/articles/web-roundups/jquery-for-absolute-beginners-video-series/
- http://resources.savedelete.com/27-best-websites-for-free-jquery-tutorials.html
Here's how it works (for more in-depth tutorial see the prettyPhoto web site)
Basic Concept
The basic idea is that you download some JavaScript, CSS and Image files and write your links with a specific syntax and add a bit of JavaScript to your page and then your gallery works. What it essentially does is hijack a link you write to a large image and instead of letting the browser go to the image it grabs the image and displays it on top of the current page with a partly see through grey background between the image and the page.
NOTE: you can use more than just images in the gallery. You can use it to show video, Flash or other sites. Read the documentation for more information.
Single Image
This is a simple example of what you would do for an image (once you've included all of the other files and script tags needed) to show it in prettyPhoto.
<a href="images/theIMG.jpg" rel="prettyPhoto" title="title here" >
<img src="images/theIMG_tb.jpg" width="80" height="80" alt="Monkeys" />
</a>
Image Gallery Tutorial
- Download the files you will need. Go to this link and click on the Production Version Compressed link.
- The file is a .zip file. Unzip it.
- Copy the js, images and css folders to your site. If you already have js, images or css folders then just copy the contents of these folders to your existing folders.
- Add the following to your HTML page inside the <head> element so that it uses the css and JavaScript files you just downloaded:
<script src="js/jquery-1.3.2.min.js" type="text/javascript"></script> <link rel="stylesheet" href="css/prettyPhoto.css" type="text/css" media="screen" title="prettyPhoto main stylesheet" charset="utf-8" /> <script src="js/jquery.prettyPhoto.js" type="text/javascript" charset="utf-8"></script>
Instead of linking to a downloaded version of jQuery I would recommend linking to a CDN hosted version like below. The only thing to worry about is that a brand new version of jQuery might break the code. So test it. The version shown works.<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js" type="text/javascript" type="text/javascript"></script> - Add this right before the closing body element on the page:
<script type="text/javascript" charset="utf-8"> $(document).ready(function(){ $("a[rel^='prettyPhoto']").prettyPhoto(); }); </script> </body>prettyPhoto shows links to twitter and facebook by default. If you don't want them to show up the add in an options object to the prettyPhoto line,like this instead of the line that starts:$("a[rel^='prettyPhoto']").prettyPhoto({social_tools:''}); - Add your thumbnails to the page with normal HTML.
- Make sure the link in the href attribute points to the large version of the image
- Add a rel attribute to your <a> element with the following syntax rel="prettyPhoto[galleryName]"Here's a photo:
Example:<a rel="prettyPhoto[myGallery]" title="Cocoa Pod" href="large1.jpg"> <img alt="picture of cocoa pod split open" src="thumb1.jpg" /> </a> <a rel="prettyPhoto[myGallery]" title="Man with a Parro" href="large2.jpg"> <img alt="Man with a Parro" src="thumb2.jpg" /> </a> <a rel="prettyPhoto[myGallery]" title="Red Umbrella" href="large2.jpg"> <img alt="Red Umbrella" src="thumb2.jpg" /> </a>Notice that the rel attribute is exactly the same each time. It doesn't change
You of course would just link to your own images. Remember that there are two images used. One is the thumbnail which is included with the img elment. If the user doesn't have Javascript then the big image will just show in a new page by itself.
Example Gallery
That’s all folks. Hopefully your gallery will be working shortly.
Fuente: http://www.teachingmultimedia.com/mmp240/prettyPhoto/#prettyPhoto
Suscribirse a:
Entradas (Atom)
Jesús Moreno - Ingeniero Ténico Informático - consultor Informático
Hola, soy Jesús Moreno Ingeniero Técnico Informático en sistemas por la US y propietario de éste blog. Mi trabajo en los ultimos años se ...
-
Para aquellos que tengáis el gusanillo de la numismática, queréis empezar a coleccionar y no podéis o no queréis hacer una gran inversión en...
-
Al intentar compartir la impresora nos lanza un error que dice: " No se pudo guardar la configuración de la impresora. No hay no hay m...
-
En una consulta LINQ que no devuelve ningún resultado y utilizamos la función First() se presenta la excepcion, “InvalidOperationException:...