The page takes time to mount a JS that mounts a <div class='Marquee'>

Asked

Viewed 39 times

0

Good morning dear friends,

I have a question here in my code that is taking my sleep, if anyone can help.

The stop to the next...

On the system screen you need to pass a (s) Mensagen(s) (HTML type Marquee) in the form of a link so that when the user clicks it is directed to the page that is on the link.

These messages are registered by a specific user so I take these messages via query and turn into links (via PHP) and use a javascript to pass the messages on the screen and when there is more than one it passes one at a time.

The code is running and do want, but it takes a while to assemble the link (run javascript), it runs the first time is the message comes out like this ( Globo Teste ) ai after a while mounts the right link that would be so the (Test Globe)

If anyone can help I appreciate.

I’m using the Yii2 Framework. BD SQL Server 2012.

I have the following code.

php that brings the BD search already separating the messages (that comes by a register) separating by , and ''. And turns the message into links to access messages directly from this link running on the page.

public static function getNoticias() {
    $models = self::find()
            ->select('ds_alerta, nm_link, nm_imagem')
            ->where('st_ativo = 1')
            ->asArray()
            ->all();

    $rec = [];
    foreach ($models as $model) {
        $imagem = '';
        $conteudo = '';

        if (empty($model['nm_link'])) {
            $conteudo = $model['ds_alerta'];
        } else {
            $conteudo = '<a href="' . $model['nm_link'] . '">' . $model['ds_alerta'] . '</a>';
        }

        if (!empty($model['nm_imagem'])) {
            $imagem = '<img src="' . $model['nm_imagem'] . '">';
        }

        $rec[] = $imagem . $conteudo;
    }

    return "'" . implode("','", $rec) . "'";
}

The Js code to run the messages one at a time. (it runs each message according to the comma that is jerada in php pessquisa.

var alertMensagens ;

$(Function () {

$('.link-menu').click(function () {
    $(this).find("span").toggleClass("glyphicon-chevron-down").toggleClass("glyphicon-chevron-right");
});

Util.urlCaminho = $('#pathCaminho').val();

$(function () {
    $(".menu-lateral-body").mCustomScrollbar({
        axis: "y",
        theme: "minimal-dark"
    });
});

$(document).ready(function () {

    $('body').on('click', 'a.manual-download', function (event) {
        event.preventDefault();

        Util.ModalAlertExclusaoJson({
            mensagem: "Clique aqui para obter o manual de utilização?",
            url: $(this).attr('href')
        });
    });

    var indice = 0;
    var tamanho = alertaMensagens.length;

    $(".marquee-text").text(alertaMensagens[indice]);

    var marquee = $('div.marquee');
    marquee.each(function () {
        var mar = $(this), indent = mar.width();
        mar.marquee = function () {
            indent--;
            mar.css('text-indent', indent);
            if (indent < -1 * mar.children('div.marquee-text').width()) {
                if ((indice + 1) > tamanho) {
                    indice = 0;
                } else {
                    indice++;
                }
                indent = mar.width();

                $(".marquee-text").html(alertaMensagens[indice]);
            }
        };
        mar.data('interval', setInterval(mar.marquee, 10 / 6000000));
    });
});

})

and my div Mom gets

alertMensagens = []; to show the Mensagen on the screen.

1 answer

0

If you have many messages it will take even, so in Sqlserver there is the OFFSET FETCH or row_number(), to limit even, imagine if the sites did not have paging, it would take hours to download the page to display/render everything.

I believe in Yii the limit() generate the query for both Sql Server and Mysql, so your code should look like this:

$models = self::find()
        ->select('ds_alerta, nm_link, nm_imagem')
        ->where('st_ativo = 1')
        ->limit(10)
        ->asArray()
        ->all();

The ->limit(10) will limit to 10 results, That’s just one example, can exchange the 10 for as many as it deems necessary, as long as it is not a very large value.

You can also choose to display randomly so that "always" different items are displayed, as shown in this response from Soen and just adapt to the use of NEWID() as shown in this reply:

$models = self::find()
        ->select('ds_alerta, nm_link, nm_imagem')
        ->where('st_ativo = 1')
        ->orderBy(new Expression('NEWID()'))
        ->limit(10)
        ->asArray()
        ->all();
  • Thanks Mano, I’ll try here, but I can tell you that even though it’s just a message, it showcases the whole href and then assembles the link.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.