magnet functionality in js