News:

Wondering if this will always be free?  See why free is better.

Main Menu

Insertar imagen a JS

Started by Pegriloco, June 21, 2020, 06:06:27 PM

Previous topic - Next topic

Pegriloco

Buenas..
alguien me da una mano de como insertar correctamente esta dirección de imagen:
<img src="' . $settings['lang_images_url'] . '/new.gif" />
a este codigo js

// Add hover events to list items if the browser requires it.
if (is_ie7down && 'attachEvent' in window)
window.attachEvent('onload', smf_addListItemHoverEvents);

$(document).ready(function(){                               
$("input[type=button],.button_submit").attr("class", "btn btn-sm btn-primary");
$("img[alt=\'"+txtnew+"'], img.new_posts").replaceWith("<span class=\'btn-new\'>"+txtnew+"</span>");
$("#profile_success").removeAttr("id").removeClass("windowbg").addClass("alert alert-success");
$("#profile_error").removeAttr("id").removeClass("windowbg").addClass("alert alert-danger");
if ($(window).width() >= 767)
$('[data-toggle="dropdown"]').bootstrapDropdownHover();
if ($('#gobacktotop').length) {
    var scrollTrigger = 100, // px
        backToTop = function () {
            var scrollTop = $(window).scrollTop();
            if (scrollTop > scrollTrigger) {
                $('#back-to-top').addClass('show');
            } else {
                $('#back-to-top').removeClass('show');
            }
        };
    backToTop();
    $(window).on('scroll', function () {
        backToTop();
    });
    $('#back-to-top').on('click', function (e) {
        e.preventDefault();
        $('html,body').animate({
            scrollTop: 0
        }, 700);
    });
}
});


en esta linea dentro de la etiqueta span
$("img[alt=\'"+txtnew+"'], img.new_posts").replaceWith("<span class=\'btn-new\'>"+txtnew+"</span>");

gracias!

Dhayzon

prueba esto

$("img[alt=\'"+txtnew+"'], img.new_posts").replaceWith("<span class=\'btn-new\'><img src=\'"+smf_images_url+"/english/new.gif\' />"+txtnew+"</span>");

Pegriloco

y si quisiera que detecte el idioma y que automaticamente cambie la imagen. ejm: de muevo a new
como sería?

Dhayzon

tendrias que modificar la imagen gif que originalmente esta en ingles, tendrias que tener dos imagenes gif con los idiomas que desees
luego declarar una variable de javascrip tipo smf_lang_images_url = "'.$settings['lang_images_url'].'";

quedaría a si

$("img[alt=\'"+txtnew+"'], img.new_posts").replaceWith("<span class=\'btn-new\'><img src=\'"+smf_lang_images_url +"/new.gif\' />"+txtnew+"</span>");



en mi opinión te traerá muchos problemas xd

Pegriloco

si tengo dos imágenes,
reemplazando la linea que me dejaste tengo este error


Dhayzon

te lo explique a grandes rasgos pero si lo vas a hacer
tienes que declarar esa variable que te dije en tu index.template.php

var smf_lang_images_url = "',$settings['lang_images_url'],'";
justo debajo de
var smf_images_url = "', $settings['images_url'], '";





Pegriloco

Gracias!
Doy por cerrado el tema

gohanjaja

Quote from: mparedes on June 21, 2020, 10:21:54 PM
si tengo dos imágenes,
reemplazando la linea que me dejaste tengo este error


Como hiciste para cargarle los iconos a los botones.. O:) :laugh:

Advertisement: