Foro de elhacker.net

Programación => PHP => Mensaje iniciado por: soru13 en 22 Enero 2012, 18:51 pm



Título: problema llamar funcion jquery con php
Publicado por: soru13 en 22 Enero 2012, 18:51 pm
hola, tengo el siguiente código

Código:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>
Jquery Lights Off Experiment
</title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#the_lights").fadeTo(1, 0);
            $(".turnon").hide();
            $(".turnoff").click(function () {
                $("#the_lights").css({ 'display': 'block' });
                $("#the_lights").fadeTo("slow", 0.8);
                $(".turnon").show();
                $(".turnoff").hide();
            });
            $(".turnon").click(function () {
                $("the_lights").css({ 'display': 'block' });
                $("#the_lights").fadeTo("slow", 0);
                $(".turnoff").show();
                $(".turnon").hide();
            });
        });
    </script>
    <style type="text/css">
        html
        {
            width: 100%;
            height: 100%;
            margin: 0px;
        }
        #the_lights
        {
            background-color: #000;
            height: 100%;
            width: 100%;
            position: absolute;
            top: 0;
            left: 0;
            display: none;
            z-index: 10;
        }
        .standout
        {
            padding: 5px;
            background-color: white;
            position: relative;
            z-index: 20;
            width:640px;
            height:390px;
            margin: 0px auto;
        }
        .button-standout
        {
            background-color: White;
            position: relative;
            z-index: 20;
            margin: 0px auto;
            width: 100px;
            height: 20px;
        }
        button
        {
            width: 100px;
            height: 20px;
        }
    </style>
</head>

<body">
    <div>
        <p>
            The Jquery Lights Off effect. This is especially useful when you are watching a
            video on a website. If you switch off the lights, the surroundings of the video
            will go dark and it will seem like you are watching a movie in a theater.</p>
    </div>
    <div id="a" class="button-standout">
        <button id="turnoff" class="turnoff" name="turnofflights">
            Lights Off</button>

        <button id="turnon" class="turnon" name="turnonlights">
            Lights On</button></div>
    <div id="standout" class="standout" align="center">
       CONTENIDO
    </div>
    <div id="the_lights">
    </div>
</body>

</html>

el caso es que funciona si le doy al botón, pero yo necesito que se ejecute cuando haga un echo en php. Llevo 2 horas mirando en internet y probando, pero no consigo nada, ¿alguien me podria ayudar?. Gracias


Título: Re: problema llamar funcion jquery con php
Publicado por: #!drvy en 22 Enero 2012, 19:30 pm
Hola,

javascript
Código
  1. function apagarLuz(){
  2.   $("#the_lights").css({ 'display': 'block' });
  3.   $("#the_lights").fadeTo("slow", 0.8);
  4.   $(".turnon").show();
  5.   $(".turnoff").hide();
  6. }
  7.  
  8. function encenderLuz(){
  9.   $("the_lights").css({ 'display': 'block' });
  10.   $("#the_lights").fadeTo("slow", 0);
  11.   $(".turnoff").show();
  12.   $(".turnon").hide();
  13. }

Para llamarlas:

Código
  1. <?php echo '<script>apagarLuz();</script>'; ?>
Código
  1. <?php echo '<script>encenderLuz();</script>'; ?>


Saludos


Título: Re: problema llamar funcion jquery con php
Publicado por: soru13 en 22 Enero 2012, 19:47 pm
Gracias hermano, funciona perfectamente.

Un saludo!  ::)